package top.hudk.tank.collider;

import top.hudk.tank.factory.Tank;
import top.hudk.tank.model.GameObject;

/**
 * 作用：
 *
 * @author hudk
 * @date 2020/9/10 23:15
 */
public class TankTankCollider implements Collider {
    @Override
    public boolean collision(GameObject o1, GameObject o2) {
        Tank tank1 = null;
        Tank tank2 = null;
        if (o1 instanceof Tank && o2 instanceof Tank) {
            tank1 = (Tank) o1;
            tank2 = (Tank) o2;
        } else {
            return true;
        }
        if (tank1.getRect().intersects(tank2.getRect())) {
            if(!tank1.isAllowCover()){
                tank1.back();
            }
            if(!tank2.isAllowCover()){
                tank2.back();
            }
            return false;
        }
        return true;
    }
}
